<?php

namespace Modules\Wechat\Model\Service\OfficialAccount;

use S\WeChat;
use Modules\Wechat\Model\Data\OfficialAccount\Menu as OaMenuData;

/**
 * 公众号菜单相关业务逻辑
 *
 * @package Modules\Wechat\Model\Service\OfficialAccount
 */
class Menu extends \Modules\Wechat\Model\Service\Abstraction
{

    /**
     * 发布公众号的菜单
     *
     * 经本地存储的菜单推送至微信服务器.
     *
     * @param string $account 公众号的微信账号t
     *
     * @return bool
     * @throws \Base\Exception\Service
     */
    public function release($account)
    {
        if ($buttons = (new OaMenuData)->getByAccountForRelease($account, true)) {
            try {
                return WeChat::app($account)->menu->add($buttons);
            } catch (\Exception $e) {
                throw new \Base\Exception\Service($e->getMessage(), $e->getCode());
            }
        }
        return false;

    }


}